package com.example.mobile2021606128wje0427;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.HashMap;
import java.util.List;

public class TingchechangAdapter extends RecyclerView.Adapter<TingchechangAdapter.ViewHolder> {
    private List<Tingchechang> list;
  //  private Object Tingchechang;

    public TingchechangAdapter(List<Tingchechang> list){
        this.list=list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //获取布局文件，创建ViewHolder对象
        View view = LayoutInflater.from( parent.getContext()).inflate( R.layout.item_rv_main_tingchechang,parent,false );
        return new ViewHolder( view );
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //绑定数据，通过positing获取数据，然后赋值给控件
        Tingchechang tingchechang = list.get(position);
        holder.tvTitle.setText( tingchechang.getTitle());
        holder.tvKongwei.setText( tingchechang.getKongwei());
        holder.tvMoney.setText( tingchechang.getMoney());
        holder.tvJvli.setText( tingchechang.getJvli());
        holder.tvAddress.setText( tingchechang.getAddress());




    }

    @Override
    public int getItemCount() {
    //    HashMap<Object, Object> list;
        return list.size();
    }

    public class  ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView tvTitle,tvKongwei,tvMoney,tvJvli,tvAddress;
        Button btnMore;
        public ViewHolder(@NonNull View itemView) {
            super( itemView );
            imageView =itemView.findViewById( R.id.iv_item_one);
            tvTitle = itemView.findViewById( R.id.tv_item_title );
            tvKongwei = itemView.findViewById( R.id.tv_item_kongwei);
            tvMoney = itemView.findViewById( R.id.tv_item_money );
            tvJvli = itemView.findViewById( R.id.tv_item_jvli );
            tvAddress = itemView.findViewById( R.id.tv_item_address );
            btnMore = itemView.findViewById( R.id.btn_item_more );
        }
    }
}
